package com.yunchuang.controller.user;

import com.yunchuang.common.BaseResult;
import com.yunchuang.model.pojo.User;
import com.yunchuang.service.UserService;
import com.yunchuang.service.impl.UserServiceImpl;
import com.yunchuang.utils.JSONUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 根据id获取用户
 *
 * @author ItJiange
 * @date 2023/10/26
 */
@WebServlet("/user/byId")
public class UserByIdController extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        // 获取查询结果
        BaseResult baseResult = userService.userById(user.getId());
//        if (ERROR_CODE == baseResult.getCode()) {
//            JSONUtils.writeOutJSON(baseResult, resp);
//            return;
//        }
        // 响应返回结果
        JSONUtils.writeOutJSON(baseResult, resp);
    }
}
